﻿using JESAI.Redis.Abstracts;
using JESAI.Redis.Abstracts.Commadns;
using JESAI.Redis.Abstracts.Commands;
using JESAI.Redis.Commands;
using JESAI.Redis.Extensions;
using JESAI.Redis.RedisClients;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace JESAI.Redis.Builders
{
    public class RedisCommandBuilder : IRedisCommandBuilder
    {
        public async Task<IRedisCommand> BuildAsync(IConnectionBuilder connectionBuilder)
        {
            if (connectionBuilder.MaxPoolSize < connectionBuilder.PoolSize)
            {
                throw new ArgumentException($"{nameof(connectionBuilder.MaxPoolSize)}不能小于最小池数量");
            }
            var redisCommand = await RedisCommand.BuilderAsync(connectionBuilder);
            //连接配置
            return redisCommand;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public async Task<IRedisCommand> BuildAsync(string connectionString)
        {
            return await BuildAsync(ConnectionBuilder.Parse(connectionString));
        }
    }
}
